﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevExpress.XtraGrid;
using GSM.BusinessLayer.DataLayer;
using GSM.BusinessLayer;

namespace CRM_SMS_MARKETING.BL
{
    class BLLContact
    {
        private void GetListWithAllCondition(string Gender, string City, string User, GridControl gridControlCustomer, List<GSM.BusinessLayer.Customer> ListCustomer)
        {
            List<GSM.BusinessLayer.Customer> list = new List<GSM.BusinessLayer.Customer>();
            int n = ListCustomer.Count;
            #region Truong hop toan bo deu rong
            if (Gender == "" && City == "" && User == "")
            {
                gridControlCustomer.DataSource = ListCustomer;
            }
            else
            #endregion

                #region Truong hop Gender!= rong
                if (Gender != "" && City == "" && User == "")
                {
                    List<GSM.BusinessLayer.Customer>  ListMale = new List<GSM.BusinessLayer.Customer>();
                    List<GSM.BusinessLayer.Customer>  ListFemale = new List<GSM.BusinessLayer.Customer>();

                    if (Gender == "Male")
                    {


                        for (int i = 0; i < n; i++)
                        {
                            if (ListCustomer[i].Gender == true)
                            {
                                ListMale.Add(ListCustomer[i]);
                            }
                        }
                        if (ListMale.Count != 0)
                        {
                            gridControlCustomer.DataSource = ListMale;
                        }
                        else
                        {
                            gridControlCustomer.DataSource = null;
                        }

                    }
                    else if (Gender == "Female")
                    {

                        
                        for (int i = 0; i < n; i++)
                        {
                            if (ListCustomer[i].Gender == false)
                            {
                                ListFemale.Add(ListCustomer[i]);
                            }
                        }
                        if (ListFemale.Count != 0)
                        {
                            gridControlCustomer.DataSource = ListFemale;
                        }
                        else
                        {
                            gridControlCustomer.DataSource = null;
                        }


                    }
                }
                else
                #endregion

                    #region Truong hop City!= rong
                    if (Gender == "" && City != "" && User == "")
                    {
                        List<GSM.BusinessLayer.Customer> ListCity = new List<GSM.BusinessLayer.Customer>();

                        for (int i = 0; i < n; i++)
                        {
                            if (ListCustomer[i].City == City)
                            {
                                ListCity.Add(ListCustomer[i]);
                            }
                        }
                        if (ListCity.Count != 0)
                        {
                            gridControlCustomer.DataSource = ListCity;
                        }
                        else
                        {
                            gridControlCustomer.DataSource = null;
                        }


                    }
                    else
                    #endregion

                        #region Truong hop User!=Rong
                        if (Gender == "" && City == "" && User != "")
                        {
                            if (User == "All")
                            {
                                gridControlCustomer.DataSource = ListCustomer;
                            }
                            else
                            {
                                List<GSM.BusinessLayer.Customer> ListUser = new List<GSM.BusinessLayer.Customer>();


                                for (int i = 0; i < n; i++)
                                {
                                    if (ListCustomer[i].User == User)
                                    {
                                        ListUser.Add(ListCustomer[i]);
                                    }
                                }
                                if (ListUser.Count != 0)
                                {
                                    gridControlCustomer.DataSource = ListUser;
                                }
                                else
                                {

                                    gridControlCustomer.DataSource = null;
                                }

                            }
                        }
                        else
                        #endregion

                            #region Truong hop Gender va City != rong
                            if (Gender != "" && City != "" && User == "")
                            {
                                List<GSM.BusinessLayer.Customer> ListCity = new List<GSM.BusinessLayer.Customer>();
                                List<GSM.BusinessLayer.Customer> ListMale = new List<GSM.BusinessLayer.Customer>();
                                List<GSM.BusinessLayer.Customer> ListFemale = new List<GSM.BusinessLayer.Customer>();
                                for (int i = 0; i < n; i++)
                                {
                                    if (ListCustomer[i].City == City)
                                    {
                                        ListCity.Add(ListCustomer[i]);
                                    }
                                }
                                if (ListCity.Count != 0)
                                {
                                    if (Gender == "Male")
                                    {
                                        int CityCount = ListCity.Count;
                                        for (int i = 0; i < CityCount; i++)
                                        {
                                            if (ListCity[i].Gender == true)
                                            {
                                                ListMale.Add(ListCity[i]);
                                            }
                                        }
                                        if (ListMale.Count != 0)
                                        {
                                            gridControlCustomer.DataSource = ListMale;
                                        }
                                        else
                                        {
                                            gridControlCustomer.DataSource = null;
                                        }
                                    }
                                    else if (Gender == "Female")
                                    {
                                        int CityCount = ListCity.Count;
                                        for (int i = 0; i < CityCount; i++)
                                        {
                                            if (ListCity[i].Gender == false)
                                            {
                                                ListFemale.Add(ListCity[i]);
                                            }
                                        }
                                        if (ListFemale.Count != 0)
                                        {
                                            gridControlCustomer.DataSource = ListFemale;
                                        }
                                        else
                                        {
                                            gridControlCustomer.DataSource = null;
                                        }

                                    }
                                }
                                else
                                {

                                    gridControlCustomer.DataSource = null;
                                }
                            }
                            else
                            #endregion

                                #region Truong hop Gender va User != rong
                                if (Gender != "" && City == "" && User != "")
                                {
                                    List<GSM.BusinessLayer.Customer>  ListUser = new List<GSM.BusinessLayer.Customer>();
                                    List<GSM.BusinessLayer.Customer> ListMale = new List<GSM.BusinessLayer.Customer>();
                                    List<GSM.BusinessLayer.Customer>  ListFemale = new List<GSM.BusinessLayer.Customer>();
                                    if (User== "All")
                                    {
                                        ListUser = ListCustomer;
                                    }
                                    else
                                    {


                                        for (int i = 0; i < n; i++)
                                        {
                                            if (ListCustomer[i].User == User)
                                            {
                                                ListUser.Add(ListCustomer[i]);
                                            }
                                        }
                                    }
                                    if (ListUser.Count != 0)
                                    {
                                        int UserCount = ListUser.Count;
                                        #region Male

                                        if (Gender == "Male")
                                        {
                                            for (int i = 0; i < UserCount; i++)
                                            {
                                                if (ListUser[i].Gender == true)
                                                {
                                                    ListMale.Add(ListUser[i]);
                                                }
                                            }
                                            if (ListMale.Count != 0)
                                            {
                                                gridControlCustomer.DataSource = ListMale;
                                            }
                                            else
                                            {
                                                gridControlCustomer.DataSource = null;
                                            }
                                        }
                                        #endregion
                                        #region Female
                                        else
                                        {
                                            for (int i = 0; i < UserCount; i++)
                                            {
                                                if (ListUser[i].Gender == false)
                                                {
                                                    ListFemale.Add(ListUser[i]);
                                                }
                                            }
                                            if (ListFemale.Count != 0)
                                            {
                                                gridControlCustomer.DataSource = ListFemale;
                                            }
                                            else
                                            {
                                                gridControlCustomer.DataSource = null;
                                            }
                                        }
                                        #endregion

                                    }
                                    else
                                    {
                                        gridControlCustomer.DataSource = null;
                                    }


                                }
                                else
                                #endregion

                                    #region Truong hop City va User != rong
                                    if (Gender == "" && City != "" && User != "")
                                    {
                                        List<GSM.BusinessLayer.Customer> ListCity = new List<GSM.BusinessLayer.Customer>();
                                        List<GSM.BusinessLayer.Customer>  ListUser = new List<GSM.BusinessLayer.Customer>();
                                        if (User == "All")
                                        {
                                            ListUser = ListCustomer;
                                        }
                                        else
                                        {

                                            for (int i = 0; i < n; i++)
                                            {
                                                if (ListCustomer[i].User == User)
                                                {
                                                    ListUser.Add(ListCustomer[i]);
                                                }
                                            }
                                        }
                                        if (ListUser.Count != 0)
                                        {
                                            int UserCount = ListUser.Count;
                                            for (int i = 0; i < UserCount; i++)
                                            {
                                                if (ListUser[i].City == City)
                                                {
                                                    ListCity.Add(ListUser[i]);
                                                }
                                            }
                                            if (ListCity.Count != 0)
                                            {
                                                gridControlCustomer.DataSource = ListCity;
                                            }
                                            else
                                            {
                                                gridControlCustomer.DataSource = null;
                                            }
                                        }
                                        else
                                        {
                                            gridControlCustomer.DataSource = null;
                                        }


                                    }
                                    else
                                    #endregion

                                        #region Truong hop Gender , User va City != rong
                                        if (Gender != "" && City != "" && User != "")
                                        {
                                            List<GSM.BusinessLayer.Customer> ListMale = new List<GSM.BusinessLayer.Customer>();
                                            List<GSM.BusinessLayer.Customer> ListFemale = new List<GSM.BusinessLayer.Customer>();
                                            List<GSM.BusinessLayer.Customer> ListCity = new List<GSM.BusinessLayer.Customer>();
                                            List<GSM.BusinessLayer.Customer> ListUser = new List<GSM.BusinessLayer.Customer>();
                                            // Lay List Customer cua User
                                            if (User == "All")
                                            {
                                                ListUser = ListCustomer;
                                            }
                                            else
                                            {

                                                for (int i = 0; i < n; i++)
                                                {
                                                    if (ListCustomer[i].User == User)
                                                    {
                                                        ListUser.Add(ListCustomer[i]);
                                                    }
                                                }
                                            }
                                            if (ListUser.Count != 0)
                                            {
                                                //Lay List City cua User
                                                int UserCount = ListUser.Count;
                                                for (int i = 0; i < UserCount; i++)
                                                {
                                                    if (ListUser[i].City == City)
                                                    {
                                                        ListCity.Add(ListUser[i]);
                                                    }
                                                }
                                                if (ListCity.Count != 0)
                                                {
                                                    int CityCount = ListCity.Count;

                                                    #region Male
                                                    if (Gender == "Male")
                                                    {
                                                        for (int i = 0; i < CityCount; i++)
                                                        {
                                                            if (ListUser[i].Gender == true)
                                                            {
                                                                ListMale.Add(ListUser[i]);
                                                            }
                                                        }
                                                        if (ListMale.Count != 0)
                                                        {
                                                            gridControlCustomer.DataSource = ListMale;
                                                        }
                                                        else
                                                        {
                                                            gridControlCustomer.DataSource = null;
                                                        }
                                                    }
                                                    #endregion

                                                    #region Female
                                                    else
                                                    {
                                                        for (int i = 0; i < UserCount; i++)
                                                        {
                                                            if (ListUser[i].Gender == false)
                                                            {
                                                                ListFemale.Add(ListUser[i]);
                                                            }
                                                        }
                                                        if (ListFemale.Count != 0)
                                                        {
                                                            gridControlCustomer.DataSource = ListFemale;
                                                        }
                                                        else
                                                        {
                                                            gridControlCustomer.DataSource = null;
                                                        }
                                                    }
                                                    #endregion
                                                }
                                                else
                                                {
                                                    gridControlCustomer.DataSource = null;
                                                }
                                            }
                                            else
                                            {
                                                gridControlCustomer.DataSource = null;
                                            }


                                        }

                                        #endregion


        }

    }
}
